package com.zkw.concurrent.executors;

import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;

/**
 * Created by Administrator on 2016/4/8.
 * 守护进程-用户线程结束时间决定守护线程
 */
public class ThreadDeamonMain {
    public class R implements Runnable{
        @Override
        public void run() {
            System.out.println("R run before");
            try {
                Thread.sleep(1000);
            System.out.println("R run after");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    public class R2 implements Runnable{
        @Override
        public void run() {
            try {
                Thread.sleep(4000);
                System.out.println("R2 run");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }
    }
    public static void main(String[] args) {
        ThreadDeamonMain test = new ThreadDeamonMain();
        R r = test.new R();
        R2 r2 = test.new R2();

        ThreadFactory threadFactory = Executors.defaultThreadFactory();
        Thread threadR = threadFactory.newThread(r);
        threadR.setDaemon(true);
        threadR.start();

        Thread threadR2 = threadFactory.newThread(r2);
        threadR2.start();


    }
}
